import { getUserInfo, setUserInfo } from '@/utils/storage'
const state = {
  userInfo: getUserInfo()
}
const getters = {
  getUserInfo (state) {
    // 实现storage持久化
    return state.userInfo
  }
}
const mutations = {
  setUserInfo (state, obj) {
    console.log(obj)
    state.userInfo = obj
    // 持久化
    setUserInfo(obj)
  }
}
const actions = {
  // 退出登录
  logouts (context) {
    // 清除userInfo  默认调用自己模块的
    context.commit('setUserInfo', { })
    // 清除购物车信息 跨模块调用mutation 需要设置 root:true  打开全局模式
    context.commit('cart/setCartList', { }, { root: true })
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
